using System;
using System.Collections.Generic;

namespace OracleInternal.I18N
{
	[Serializable]
	internal abstract class TLBConv : Conv
	{
		public const int CHARCONV1BYTEID = 0;

		public const int CHARCONV12BYTEID = 1;

		public const int CHARCONVJAEUCID = 2;

		public const int CHARCONVLCFIXEDID = 3;

		public const int CHARCONVSJISID = 4;

		public const int CHARCONVZHTEUCID = 5;

		public const int CHARCONV2BYTEFIXEDID = 6;

		public const int CHARCONVSHIFTID = 7;

		public const int CHARCONVLCID = 8;

		public const int CHARCONVGB18030ID = 9;

		public const int CHARCONVAL16UTF16ID = 10;

		public const int CHARCONVMSOLISO2022JPFWID = 11;

		public const int CHARCONVMSOLISO2022JPHWID = 12;

		public const int CHARCONVGBKID = 13;

		private const string CONVERTERNAMEPREFIX = "lx2";

		private const string CONVERTERIDPREFIX = "0000";

		public const byte UNDEFINED_DISPLAY_WIDTH = byte.MaxValue;

		public const int BELOW_CJK = 12287;

		protected const int HIBYTEMASK = 65280;

		protected const int LOWBYTEMASK = 255;

		protected const int STORE_INCREMENT = 10;

		protected const char CHAR_INVALID_ORA_CHAR = '\uffff';

		protected const int FIRSTBSHIFT = 24;

		protected const int SECONDBSHIFT = 16;

		protected const int THIRDBSHIFT = 8;

		protected const int UB2MASK = 65535;

		protected const int UB4MASK = 65535;

		protected const string BEGIN_UNISTR = "UNISTR('";

		protected const string END_UNISTR = "')";

		private static Dictionary<string, TLBConv> m_converterStore = new Dictionary<string, TLBConv>();

		internal int m_groupId;

		public int[][] extraUnicodeToOracleMapping;

		public TLBConv()
		{
		}

		protected TLBConv(int oracleId)
			: base(oracleId)
		{
		}

		public static TLBConv GetGLBInstance(int oraId)
		{
			TLBConv tLBConv = null;
			string text = $"{oraId:X}";
			if (m_converterStore.ContainsKey(text))
			{
				return m_converterStore[text];
			}
			tLBConv = (TLBConv)TLBConvBoot.ReadObj(string.Concat("lx2" + "0000".Substring(0, 4 - text.Length) + text, ".glb"));
			if (tLBConv == null)
			{
				return null;
			}
			tLBConv.BuildUnicodeToOracleMapping();
			m_converterStore.Add(text, tLBConv);
			return tLBConv;
		}

		protected void StoreMappingRange(int ucsCodePt, Dictionary<int, char[]> htable, Dictionary<int, char[]> htable2)
		{
			int num = (ucsCodePt >> 24) & 0xFF;
			int num2 = (ucsCodePt >> 16) & 0xFF;
			int num3 = (ucsCodePt >> 8) & 0xFF;
			int num4 = ucsCodePt & 0xFF;
			int key = num;
			int key2 = (ucsCodePt >> 16) & 0xFFFF;
			int key3 = (ucsCodePt >> 8) & 0xFFFFFF;
			int num5 = 0;
			int num6 = 26;
			num5 = ((ucsCodePt < 0) ? ((ucsCodePt >> num6) + (2 << ~num6)) : (ucsCodePt >> num6));
			char[] array;
			if (num5 == 54)
			{
				array = (htable.ContainsKey(key) ? htable[key] : new char[2]
				{
					'ÿ',
					'\0'
				});
				if (array[0] == 'ÿ' && array[1] == '\0')
				{
					array[0] = (char)num2;
					array[1] = (char)num2;
				}
				else
				{
					if (num2 < (array[0] & 0xFFFF))
					{
						array[0] = (char)num2;
					}
					if (num2 > (array[0] & 0xFFFF))
					{
						array[1] = (char)num2;
					}
				}
				if (!htable.ContainsKey(key))
				{
					htable.Add(key, array);
				}
				array = (htable.ContainsKey(key2) ? htable[key2] : new char[2]
				{
					'ÿ',
					'\0'
				});
				if (array[0] == 'ÿ' && array[1] == '\0')
				{
					array[0] = (char)num3;
					array[1] = (char)num3;
				}
				else
				{
					if (num3 < (array[0] & 0xFFFF))
					{
						array[0] = (char)num3;
					}
					if (num3 > (array[0] & 0xFFFF))
					{
						array[1] = (char)num3;
					}
				}
				if (!htable.ContainsKey(key2))
				{
					htable.Add(key2, array);
				}
			}
			array = (htable2.ContainsKey(key3) ? htable2[key3] : new char[2]
			{
				'ÿ',
				'\0'
			});
			if (array[0] == 'ÿ' && array[1] == '\0')
			{
				array[0] = (char)num4;
				array[1] = (char)num4;
			}
			else
			{
				if (num4 < (array[0] & 0xFFFF))
				{
					array[0] = (char)num4;
				}
				if (num4 > (array[0] & 0xFFFF))
				{
					array[1] = (char)num4;
				}
			}
			if (!htable2.ContainsKey(key3))
			{
				htable2.Add(key3, array);
			}
		}

		public int GetGroupId()
		{
			return m_groupId;
		}

		public abstract bool IsOraCharacterReplacement(char ch, char lowsur);

		public abstract void BuildUnicodeToOracleMapping();

		public abstract void ExtractCodepoints(IList<int[]> vtable);

		public abstract void ExtractExtraMappings(IList<int[]> vtable);

		public abstract bool HasExtraMappings();

		public abstract char GetOraChar1ByteRep();

		public abstract char GetOraChar2ByteRep();

		public abstract int GetUCS2CharRep();

		public char[] GetLeadingCodes()
		{
			return null;
		}
	}
}
